Skip to content

feat(sdk): add settings file and layered resolver for targets, platforms and secret stores - #690

Merged
dmealing merged 2 commits into
mainfrom
fm/mo-140-w0-s1
Dec 2, 2026
Merged

dmealing merged 2 commits into
mainfrom
fm/mo-140-w0-s1

Conversation

@dmealing

@dmealing dmealing commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Adds .metaobjects/settings.json, read by TypeScript only. It carries targets, platforms, resourceDefaults (keyed by platform, then resource kind), purposes, environments and secrets.stores. It may extends a shared estate file (relative path or package), merged key by key with the nearer file winning. config.json gains no keys.
  • @metaobjectsdev/sdk exports loadSettings, loadSettingsFile, the SettingsFileSchema and a SettingsError with stable error codes. It also exports a resolver (resolveTarget, resolveResource, resolveApp, resolveGeneratedStore, resolveAdoptedStore) that reports each value with the layer and file it came from. Layers are generator default, resource defaults, purpose, then environment.
  • Adds unit tests for layer precedence and three fixture settings files (test/fixtures/settings/setup-{a,b,c}.settings.json) that parse and resolve. Adds docs/features/settings.md, a docs/README.md index entry, and a changelog fragment. The feature is experimental. No generator reads the settings yet, and a project without a settings file sees no change. metamodelVersion does not move.
Validation

Risk Assessment

✅ Low: Additive TypeScript-only settings reader and resolver with no generator consumers yet. The round-1 gaps (platform-key checks, Object.prototype lookups) are closed with tests, and the intent's required layers, three setup files and extends are all present.

Testing

Ran the S1 settings unit tests (24 pass) and a live bun driver against the real sdk loader and resolver. The three setup files load, layer precedence resolves as specified, the review-1 typo refusals fire, prototype names do not resolve, and extends overrides key by key. All scenarios passed live against local fixtures. Broad regression came from the configured baseline command, which passed. The review-2 question was decided: extends keeps the package-specifier mode, because shared estate settings live in another repository; that mode and its not-found branch are covered by the unit tests.

  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Load the three design setup files (A, B, C) through loadSettingsFile ✅ pass live s1-settings-resolver-drive.log: setup-a/b/c loaded (6/10/7 targets)
Layer precedence: generator < resourceDefaults < purpose < environment provision ✅ pass live s1-settings-resolver-drive.log and env.ts output: 18 > 17 > 16; purpose 35 > generator 7
Adversarial: typo platform in resourceDefaults and secrets.generated refused ✅ pass live s1-settings-resolver-drive.log: ERR_SETTINGS_UNKNOWN_PLATFORM for both
Adversarial: prototype name toString is not resolved as a target ✅ pass live s1-settings-resolver-drive.log: ERR_SETTINGS_UNKNOWN_TARGET
extends: project overrides estate key by key ✅ pass live s1-settings-resolver-drive.log extends layering line
extends package-specifier mode ✅ decided no Kept by decision; resolution and its not-found branch are covered by unit tests in settings.test.ts.
Evidence: Settings resolver live driver log
setup-a loaded; targets: 6 platforms: aws
setup-b loaded; targets: 10 platforms: aws,railway,docker
setup-c loaded; targets: 7 platforms: docker
setup-b resourceDefaults: {"aws":{"rdb":{"product":"aurora-postgresql","version":"17"},"keyValue":{"product":"elasticache-valkey","version":"8"},"objectStore":{"product":"s3"},"document":{"product":"documentdb","version":"8.0"},"search":{"product":"opensearch-service","version":"3.1"},"queue":{"product":"sqs"},"stream":{"product":"msk","version":"4.1"}},"railway":{"rdb":{"product":"railway-postgres"},"keyValue":{"product":"railway-redis"}},"docker":{"rdb":{"product":"postgres","version":"18"},"objectStore":{"product":"seaweedfs"},"queue":{"product":"rabbitmq","version":"4.4"}}}
setup-b purposes: ["production","staging","test","development"] envs: ["Production","Staging"]
resolved rdb aws-eu-west: [["product","aurora-postgresql","resourceDefaults"],["version","17","resourceDefaults"],["backupDays",35,"purpose"]]
typo resourceDefaults: ERR_SETTINGS_UNKNOWN_PLATFORM
typo secrets.generated: ERR_SETTINGS_UNKNOWN_PLATFORM
proto: ERR_SETTINGS_UNKNOWN_TARGET
toString target: ERR_SETTINGS_UNKNOWN_TARGET
extends layering: [["product","postgres","resourceDefaults","estate.json"],["version","16","resourceDefaults","project.json"]]
[["backupDays",35,"purpose"],["product","postgres","resourceDefaults"],["version","18","environment"]]
[["backupDays",35,"purpose"],["product","postgres","resourceDefaults"],["version","17","purpose"]]
  • Outcome: ✅ passed; the one test warning (review-2) was decided by the operator (6m54s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ✅ Fixed. server/typescript/packages/sdk/src/settings.ts:302 - checkNames validates only some of the keys that name a platform. A target's platform and the secrets.targets keys are checked. The resourceDefaults platform keys and the secrets.generated platform keys are not checked. A typo such as resourceDefaults.dokcer.rdb or secrets.generated.dokcer loads clean. Then resolveResource silently falls back to the generator default product and version (settings.ts:440-441), and resolveGeneratedStore silently returns undefined (settings.ts:487-489). Both give a wrong answer without an error, which is the typo trap the schema comment at settings.ts:60-63 says the file guards against. Related problem: all membership tests use the in operator (settings.ts:305, :321, :326), which also matches Object.prototype names. A platform, store or target named constructor or toString passes the check, and the resolver then reads a function from data.platforms[...], secrets.stores[...] or data.targets[...] (settings.ts:385, :392, :489, :496). Fix: in checkNames, refuse a resourceDefaults key or secrets.generated key that is not under platforms, with ERR_SETTINGS_UNKNOWN_PLATFORM. Use Object.hasOwn for every membership test. All three setup fixtures already satisfy the stricter check. Add a test case for each new refusal.
  • ✅ Kept by decision (shared estate settings live in another repository, so a published package is the cross-repo path; docs say so). server/typescript/packages/sdk/src/settings.ts:232 - Simplification: extends accepts two resolution modes. One is a path relative to the extending file. The other is a bare package specifier, resolved through createRequire(fromFile).resolve (settings.ts:240-247, tested at settings.test.ts:216, documented in docs/features/settings.md). The intent asks only for extends to a shared estate file that a project extends. A relative path satisfies that. The package-specifier mode adds a node_modules resolution path, a second failure branch, and a public contract that is beyond what the stated scope requires, unless the round-1 layering design calls for package-published estate files. That design is not in the repository, so this review could not confirm it. Recommend removing the package-specifier mode unless the design requires it.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed (review-2 decided by the operator)
  • ✅ Decided: keep the package-specifier mode of extends (the review-2 ruling); approved by the operator.
  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Load the three design setup files (A, B, C) through loadSettingsFile ✅ pass live s1-settings-resolver-drive.log: setup-a/b/c loaded (6/10/7 targets)
Layer precedence: generator < resourceDefaults < purpose < environment provision ✅ pass live s1-settings-resolver-drive.log and env.ts output: 18 > 17 > 16; purpose 35 > generator 7
Adversarial: typo platform in resourceDefaults and secrets.generated refused ✅ pass live s1-settings-resolver-drive.log: ERR_SETTINGS_UNKNOWN_PLATFORM for both
Adversarial: prototype name toString is not resolved as a target ✅ pass live s1-settings-resolver-drive.log: ERR_SETTINGS_UNKNOWN_TARGET
extends: project overrides estate key by key ✅ pass live s1-settings-resolver-drive.log extends layering line
extends package-specifier mode ✅ decided no Kept by decision; resolution and its not-found branch are covered by unit tests in settings.test.ts.
  • scripts/ci-local.sh --affected --strict-toolchains
  • bun test packages/sdk/test/settings.test.ts (in server/typescript): 24 pass, 0 fail
  • Live bun driver importing packages/sdk/src/index.ts: loadSettingsFile on setup-a, setup-b, setup-c fixtures
  • Precedence: resolveResource on setup-b aws-eu-west rdb across generator, resourceDefaults, purpose and environment layers
  • Adversarial: resourceDefaults key dokcer and secrets.generated key dokcer refused with ERR_SETTINGS_UNKNOWN_PLATFORM
  • Adversarial: resolveTarget(toString) refused with ERR_SETTINGS_UNKNOWN_TARGET
  • extends: project overrides estate key by key
  • Environment precedence: provisions.db1 version 18 over purpose 17 over resourceDefaults 16
  • Broad regression: configured command scripts/ci-local.sh --affected --strict-toolchains at this target, passing (baseline; not re-run)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…re, with a layered resolver

.metaobjects/settings.json, read by TypeScript only (ADR-0070, calls 5 and 13): targets,
platforms, resourceDefaults keyed by platform then kind, purposes, environments and
secrets.stores, with an extends chain merged key by key. The resolver answers which target,
product, size and secret store a node gets, and which layer and file each value came from.
The design's three complete setup files are test fixtures and resolve as written.
@dmealing
dmealing merged commit f7bb0e1 into main Dec 2, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-140-w0-s1 branch December 2, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant